﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Albon.Model;
namespace BLL
{
    public class MenuBLL
    {
        private readonly DAL.MenuDAL menudal = new DAL.MenuDAL();
        /// <summary>
        /// 添加或修改menu,当ID为0时添加，ID不为0时修改相应menu信息,成功则返回true
        /// </summary>
        public bool alterMenu(Menu menu)
        {
           return menudal.alterMenu(menu);
        }
        /// <summary>
        /// 判断一个菜单名称是否已经存在,id=0是添加时的判断 ，id不等于0是修改时的判断
        /// </summary>
        public bool Exist(int id,string menuname)
        {
            return menudal.Exist(id,menuname);
        }
        /// <summary>
        /// 删除一条数据,当前菜单不存在子菜单，则删除成功，返回0，若存在子菜单，则返回子菜单个数，并提示
        /// 删除所有子菜单后才能删除该菜单 
        /// </summary>
        public string delMenu(int id)
        {
            if (menudal.delMenu(id) != 0)
            {
                return "Can not delete menu that has Child";
            }
            return "Delete Success!";
        }

        public DataTable getMenuByID(string id)
        {
            return menudal.getMenu("ID="+id);
        }

        public DataTable getMenuByPid(string pid)
        {
            return menudal.getMenu("parentID="+pid);
        }
    }
}
